
from game import Hall
from OUAT_Hall import OUATHall
from Bang_Hall import BangHall

class GameHall(Hall):
    def __init__(self, profile,conf,conn, reactor, users=[],):
        Hall.__init__(self, profile, conf, conn, reactor, users)

    def newHandler(self,who,msg):
        '"/new player1 player2..." Start a new game'
        if msg == '':
            self.systoone(who, 'Usage: /new player1 player2...')
        else:
            players = msg.split()
            player_list = []
            admin = self.getindexname(who)
            for player in players:
                name = self.getindexname(player)
                if name in self.user_list:
                    if name not in player_list and name != admin:
                        player_list.append(name)
                else:
                    self.systoone(who, "Can't find the specific player: %s"%player)
                    return
            
            new_game = OUATHall(admin,self.profile, self.conf, self.conn, self.reactor, player_list)

            self.user_list = [x for x in self.user_list if x not in player_list and x != admin]
            #self.systoall("(%s) have joined a game"%" ".join(player_list.append(admin)),butnot=player_list.append(admin))
            self.systoone(who,'%s have joined your game!'%" ".join(player_list))
            self.room_list.append(new_game)
        pass
    
    def newbangHandler(self, who, msg):
        '"/newBang player1 player2..." Start a new Bang Game'
        if msg == '':
            self.systoone(who, 'Usage: /newBang player1 player2...')
        else:
            players = msg.split()
            player_list = []
            admin = self.getindexname(who)
            for player in players:
                name = self.getindexname(player)
                if name in self.user_list:
                    if name not in player_list and name != admin:
                        player_list.append(name)
                else:
                    self.systoone(who, "Can't find the specific player: %s" % player)
                    return

            new_game = BangHall(admin, self.profile, self.conf, self.conn, self.reactor, player_list)

            self.user_list = [x for x in self.user_list if x not in player_list and x != admin]
            self.systoone(who, '%s have joined your game!' % " ".join(player_list))
            self.room_list.append(new_game)
